package Vista;

import java.awt.BorderLayout;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.BoxLayout;
import javax.swing.JLabel;
import java.awt.Component;
import javax.swing.JTextField;
import java.awt.Dimension;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.Font;
import java.awt.Color;

public class VistaAltaUsuario extends JDialog {

	private static final long serialVersionUID = 1L;
	private final JPanel contentPanel = new JPanel();
	private JButton cancelButton;
	private JButton okButton;
	private JTextField textFieldNomUsuario;
	private JTextField txtContrasenia;
	private JLabel lblError;


	public VistaAltaUsuario(JFrame padre) {
		super(padre);
		setTitle("Dar Alta Usuario");
		setUndecorated(true);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		contentPanel.setLayout(new BorderLayout(0, 0));
		{
			JPanel panel = new JPanel();
			contentPanel.add(panel, BorderLayout.WEST);
			panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
			{
				JLabel lblNomUsuario = new JLabel("Nombre de Usuario");
				lblNomUsuario.setBorder(new EmptyBorder(3, 0, 3, 0));
				lblNomUsuario.setAlignmentX(Component.RIGHT_ALIGNMENT);
				panel.add(lblNomUsuario);
			}
			{
				JLabel lblContrasenia = new JLabel("Contrase\u00F1a");
				lblContrasenia.setAlignmentX(Component.RIGHT_ALIGNMENT);
				panel.add(lblContrasenia);
			}
		}
		{
			JPanel panel = new JPanel();
			panel.setBorder(new EmptyBorder(0, 5, 0, 0));
			contentPanel.add(panel, BorderLayout.CENTER);
			panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
			{
				textFieldNomUsuario = new JTextField();
				textFieldNomUsuario.setAlignmentX(Component.LEFT_ALIGNMENT);
				textFieldNomUsuario.setMaximumSize(new Dimension(150, 22));
				panel.add(textFieldNomUsuario);
				textFieldNomUsuario.setColumns(10);
			}
			{
				txtContrasenia = new JTextField();
				txtContrasenia.setAlignmentX(Component.LEFT_ALIGNMENT);
				txtContrasenia.setMaximumSize(new Dimension(150, 22));
				panel.add(txtContrasenia);
				txtContrasenia.setColumns(10);
			}
		}
		{
			lblError = new JLabel("Error de alg\u00FAn tipo como que no exista un usuario o en la base de datos");
			lblError.setAlignmentX(Component.CENTER_ALIGNMENT);
			lblError.setForeground(Color.RED);
			lblError.setFont(new Font("Tahoma", Font.PLAIN, 15));
			lblError.setToolTipText("");
			contentPanel.add(lblError, BorderLayout.SOUTH);
		}
		{
			JPanel buttonPane = new JPanel();
			getContentPane().add(buttonPane, BorderLayout.SOUTH);
			buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.X_AXIS));
			{
				okButton = new JButton("Guardar");
				okButton.setAlignmentX(Component.CENTER_ALIGNMENT);
				okButton.setActionCommand("OK");
				buttonPane.add(okButton);
			}
			{
				cancelButton = new JButton("Cancelar");
				cancelButton.setAlignmentX(Component.RIGHT_ALIGNMENT);
				cancelButton.setActionCommand("Cancel");
				buttonPane.add(cancelButton);
			}
		}
		
		pack();
		ubicarVentana();

		padre.addComponentListener(new ComponentAdapter() {
			@Override
			public void componentMoved(ComponentEvent e) {
				ubicarVentana();
			}
			@Override
			public void componentResized(ComponentEvent evt) {
				ubicarVentana();
			}
		});
	}
	
	public JButton getBtnCancelar(){
		return cancelButton;
	}

	private void ubicarVentana(){
		this.setLocation(((JFrame)getParent()).getContentPane().getLocationOnScreen());
	}

	public JButton getokButtom(){
		return okButton;
	}

	public JTextField getTextNomUsuario(){
		return textFieldNomUsuario;
	}

	public JTextField getTxtContrasenia() {
		return txtContrasenia;
	}

	public JLabel getLblError() {
		return lblError;
	}
	
}
